<template>
  <view>
    <u-navbar
      height="50"
      title="发表评价"
      title-width="300"
      title-color="#333"
      title-size="36"
    ></u-navbar>
    <view class="contentView">
      <view :key="index">
        <view class="goodsView">
          <!-- <u-image width="120" height="120" border-radius="10" :src="item.img"></u-image> -->
          <view class="goodsData">
            <text class="goodsTitle">队该施工队进行评价</text>
            <view class="goodsStar">
              <view>评分</view>
              <u-rate :count="5" v-model="form.score" size="38" active-color="#FFCA14"></u-rate>
            </view>
          </view>
        </view>
        <view class="inputView">
          <textarea
            class="inputText"
            v-model="form.content"
            placeholder="请输入您的评价..."
          ></textarea>
          <view class="uploadView">
            <u-upload
              ref="uUpload"
              :action="action"
              width="200"
              height="200"
              :show-progress="false"
              max-count="5"
              @on-change="onUpload"
              @on-remove="onRemove"
            >
            </u-upload>
          </view>
        </view>
      </view>
    </view>
    <view class="submitView">
      <view class="submitBtn" @click="onPostData()">提交评价</view>
    </view>
  </view>
</template>

<script>
import { BASE_URL, UP_URL } from '../../common/config.js'
export default {
  data() {
    return {
      value: 0,
      action: BASE_URL + UP_URL,
      id: '',
      form: {
        projectId: '',
        scores: 5,
        content: '',
        picUrls: []
      }
    }
  },
  onLoad(options) {
    this.form.projectId = options.id
  },
  methods: {
    onPostData() {
      this.$refs.uUpload.lists.forEach((val) => {
        if (val.response) {
          this.form.picUrls.push(val.response.data)
        }
      })

      uni.dialog.confirm('温馨提示', '确认评论？', () => {
        this.$u.post('/app-api/construction/project-comment/create', this.form).then((res) => {
          this.$u.toast('成功')
          setTimeout(() => {
            uni.navigateBack()
          }, 800)
        })
      })
    }
  }
}
</script>

<style>
@import url('push-comment.css');

page {
  background: #eeeeef;
}
</style>
